<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('表单元素字典列表')"/>
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" name="dictParent" value="0" />
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>字典代码：</p>
                                <input type="text" name="dictCode"/>
                            </li>
                            <li>
                                <p>字典描述：</p>
                                <input type="text" name="dictTitle"/>
                            </li>
                            <li>
                                <p>字典类型：</p>
                                <select name="dictType" th:with="type=${@dict.getType('form_dict_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                            th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="form:dict:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
                   shiro:hasPermission="form:dict:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
                   shiro:hasPermission="form:dict:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<div class="ui-layout-east">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 字典子元素
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="removeSubDict()" title="删除字典"><i class="fa fa-remove"></i></a>
                <a type="button" class="btn btn-box-tool" href="#" onclick="editSubDict()" title="修改字典"><i class="fa fa-edit"></i></a>
            </div>
        </div>
        <div class="ui-layout-content" style="overflow: scroll">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('form:dict:edit')}]];
    var removeFlag = [[${@permission.hasPermi('form:dict:remove')}]];
    var yesNoDatas = [[${@dict.getType('sys_yes_no')}]];
    var prefix = ctx + "form/dict";
    var selectParentTreeId=0;
    $(function () {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, east__size: 285 });
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add/{id}",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            importUrl: prefix + "/importData",
            importTemplateUrl: prefix + "/importTemplate",
            modalName: "表单元素字典",
            onClickRow:function(row,$element){querySubDictTree(row.dictId)},
            columns: [{
                radio: true
            },
                {
                    field: 'dictId',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'dictCode',
                    title: '字典代码'
                },
                {
                    field: 'dictTitle',
                    title: '字典描述'
                },
                {
                    field: 'dictType',
                    title: '字典类型'
                },
                {
                    field: 'dictScore',
                    title: '得分'
                },
                {
                    field: 'dictExpend',
                    title: '纵向扩展',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(yesNoDatas, value);
                    }
                },
                {
                    field: 'dictParent',
                    title: '父字典',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    width:  200,
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.dictId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.dictId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function querySubDictTree(parentId)
    {
        selectParentTreeId=parentId;
        var url = ctx + "form/dict/treeData/"+parentId;
        var options = {
            url: url,
            expandLevel: 0,
            onClick: function(event, treeId, treeNode){
                selectParentTreeId=treeNode.id;
            }
        };
        $.tree.init(options);
    }

    function editSubDict(){
        if(selectParentTreeId==0){
            $.modal.msgError("请选择节点");
            return;
        }
        $.operate.edit(selectParentTreeId)
    }
    function removeSubDict(){
        var selected=$.tree.getSelectedNodes();
        if(selected==""){
            $.modal.msgError("请选择节点");
            return;
        }
        $.modal.confirm("确定删除该条吗？", function() {
             $.operate.post(prefix + "/remove",{"ids":selected},function () {
                 dictId = $.table.selectFirstColumns();
                 querySubDictTree(dictId);
             });
        });
    }

    function add(){
        $.operate.add(selectParentTreeId);
    }
</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                &nbsp;	<a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>